<?php
/*
 *  Copyright (c) 2014 The CCP project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a Beijing Speedtong Information Technology Co.,Ltd license
 *  that can be found in the LICENSE file in the root of the web site.
 *
 *   http://www.yuntongxun.com
 *
 *  An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

include_once("CCPRestSDK.php");
/**
  * 发送模板短信
  * @param to 手机号码集合,用英文逗号分开
  * @param datas 内容数据 格式为数组 例如：array('Marry','Alon')，如不需替换请填 null
  * @param $tempId 模板Id
  */       
function sendTemplateSMS($to,$datas,$tempId)
{
     // 初始化REST SDK
     global $accountSid,$accountToken,$appId,$serverIP,$serverPort,$softVersion;
     //主帐号
//     $accountSid= $Sid;
   $accountSid= 'aaf98f8953cadc690153ea6cac4f56cc';

    //主帐号Token
//     $accountToken= $Token;
   $accountToken= 'fdc17492b6c043c4b1132252feebcb71';

    //应用Id
    //$appId=$app;
   $appId='aaf98f8953ea8e8c01540a9f8991357b';
//    (开发) Rest URL：https://sandboxapp.cloopen.com:8883
//(生产) Rest URL：https://app.cloopen.com:8883
    //请求地址，格式如下，不需要写https://
    $serverIP='sandboxapp.cloopen.com';

    //请求端口 
    $serverPort='8883';
    //REST版本号
     $softVersion='2013-12-26';
     $rest = new REST($serverIP,$serverPort,$softVersion);
     $rest->setAccount($accountSid,$accountToken);
     $rest->setAppId($appId);
    
     // 发送模板短信
     //echo "Sending TemplateSMS to $to <br/>";
     $result = $rest->sendTemplateSMS($to,$datas,$tempId);
     if($result == NULL ) {
//         echo "result error!";
     }
     if($result->statusCode!=0) {
     	$codes = array('code'=>$result->statusCode,'msg'=>$result->statusMsg);
     	return $codes;
//         echo "error code :" . $result->statusCode . "<br>";
//         echo "error msg :" . $result->statusMsg . "<br>";
         //TODO 添加错误处理逻辑
     }else{
        
//          echo "Sendind TemplateSMS success!<br/>";
         // 获取返回信息
         $smsmessage = $result->TemplateSMS;
//          echo "dateCreated:".$smsmessage->dateCreated."<br/>";
//          echo "smsMessageSid:".$smsmessage->smsMessageSid."<br/>";
         //TODO 添加成功处理逻辑
         
         return 10050;
     }
}
//sendTemplateSMS('13146735385',array(''),30481);
?>
